package com.ruoyi.project.warehouse.controller;

import java.util.Date;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.project.warehouse.domain.RyDepotItemVo;
import com.ruoyi.project.warehouse.domain.RyDepotRecordAuditVo;
import com.ruoyi.project.warehouse.service.IRyDepotRecordAuditService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.warehouse.domain.OutRyDepotItem;
import com.ruoyi.project.warehouse.service.IOutRyDepotItemService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 出库Controller
 *
 * @author you
 * @date 2022-09-07
 */
@RestController
@RequestMapping("/warehouse/OutRyDepotItem")
public class OutRyDepotItemController extends BaseController
{
    @Autowired
    private IOutRyDepotItemService outRyDepotItemService;

    @Autowired
    private IRyDepotRecordAuditService ryDepotRecordAuditService;

    /**
     * 查询出库列表
     */
    @PreAuthorize("@ss.hasPermi('warehouse:OutRyDepotItem:list')")
    @GetMapping("/list")
    public TableDataInfo list(OutRyDepotItem outRyDepotItem)
    {
        startPage();
        List<RyDepotItemVo> list = outRyDepotItemService.selectOutRyDepotItemList(outRyDepotItem);
        return getDataTable(list);
    }

    /**
     * 导出出库列表
     */
    @PreAuthorize("@ss.hasPermi('warehouse:OutRyDepotItem:export')")
    @Log(title = "出库", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, OutRyDepotItem outRyDepotItem)
    {
        List<RyDepotItemVo> list = outRyDepotItemService.selectOutRyDepotItemList(outRyDepotItem);
        ExcelUtil<RyDepotItemVo> util = new ExcelUtil<RyDepotItemVo>(RyDepotItemVo.class);
        util.exportExcel(response, list, "出库数据");
    }

    /**
     * 获取出库详细信息
     */
    @PreAuthorize("@ss.hasPermi('warehouse:OutRyDepotItem:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(outRyDepotItemService.selectOutRyDepotItemById(id));
    }

    /**
     * 新增出库
     */
    @PreAuthorize("@ss.hasPermi('warehouse:OutRyDepotItem:add')")
    @Log(title = "出库", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody RyDepotItemVo ryDepotItemVo)
    {
        return toAjax(outRyDepotItemService.insertOutRyDepotItem(ryDepotItemVo));
    }

    /**
     * 修改出库
     */
    @PreAuthorize("@ss.hasPermi('warehouse:OutRyDepotItem:edit')")
    @Log(title = "出库", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody RyDepotRecordAuditVo ryDepotRecordAuditVo)
    {
        return toAjax(ryDepotRecordAuditService.insertRyDepotRecordAudit(ryDepotRecordAuditVo,"出库"));
    }

    /**
     * 删除出库
     */
    @PreAuthorize("@ss.hasPermi('warehouse:OutRyDepotItem:remove')")
    @Log(title = "出库", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(outRyDepotItemService.deleteOutRyDepotItemByIds(ids));
    }
}
